using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ItemObject : MonoBehaviour
{
    public ItemData itemData;
    public UIItemSlot ui;
    private Rigidbody2D rb2d=>GetComponent<Rigidbody2D>();
   private Vector2 velocity; 
    private void OnValidate()
    {
        SetupItemName();
    }
    private void SetupItemName()
    {
        if (itemData == null) return;
        GetComponent<SpriteRenderer>().sprite = itemData.itemSprite;
        gameObject.name = "Item_" + itemData.itemName;
    }

    public void SetupItem(ItemData itemData,Vector2 velocity)
    {
        this.itemData = itemData;
        rb2d.velocity = velocity;
        SetupItemName();
    }
    public void PickUp(Collider2D collision)
    {
        if (!Inventory.Instance.CanGetItem())
        {
            rb2d.velocity = new Vector2(0, 7);
            return;
        } 
        if (collision.GetComponent<Player>() == null) return;
        Inventory.Instance.AddItem(gameObject.GetComponent<ItemObject>().itemData);
        Destroy(gameObject);
    }
}
